package chances.epg.navigator.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import chances.epg.navigator.EpgConstants;
import chances.epg.navigator.EpgLogUtils;
import chances.epg.navigator.context.AccessContext;
import chances.epg.session.UserSessionHelper;


/**
 * 用于记录访问日志的拦截器.
 * @author Elysium
 *
 */

@Component
public class AccessLogInterceptor extends HandlerInterceptorAdapter {
	@Override
	public void afterCompletion(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		AccessContext context = (AccessContext)request.getAttribute(EpgConstants.EPG_CONTEXT);
		if(context != null) {
			EpgLogUtils.logAccess(request,context,UserSessionHelper.getUserSession(request));
		}
		
		super.afterCompletion(request, response, handler, ex);
	}
}